lib/prune: speed up pruning by retrieving only commits
authorSaqib Ali <saqali@redhat.com>
Mon, 6 Jun 2022 21:46:01 +0000 (17:46 -0400)
committerSaqib Ali <saqali@redhat.com>
Mon, 27 Jun 2022 12:04:50 +0000 (08:04 -0400)
After landing the new --commit-only functionality, we still noticed
exceedingly long pruning times in large repos. Lets add an optimization
that will only retrieve commit objects when --commit-only flag is used.

src/libostree/ostree-repo-prune.c
src/libostree/ostree-repo.h

index da4f4284c0955a49a5bff8ee2c5c4f7dec62245e..e53b816342df1f9ca9f2ce0c4f6e92234f4d9f0b 100644 (file)
@@ -189,7 +189,6 @@ _ostree_repo_prune_tmp (OstreeRepo *self,
   return TRUE;
 }
 
-
 /**
  * ostree_repo_prune_static_deltas:
  * @self: Repo
@@ -437,8 +436,17 @@ ostree_repo_prune (OstreeRepo        *self,
         return FALSE;
     }
 
-  objects = ostree_repo_list_objects_set (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS,
+  if (commit_only)
+    {
+      if (!ostree_repo_list_commit_objects_starting_with (self, "", &objects, cancellable, error))
+        return FALSE; 
+    }
+  else 
+    {
+      objects = ostree_repo_list_objects_set (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS,
                                           cancellable, error);
+    }
+
   if (!objects)
     return FALSE;
 
@@ -508,9 +516,20 @@ ostree_repo_prune_from_reachable (OstreeRepo        *self,
   if (!lock)
     return FALSE;
 
-  g_autoptr(GHashTable) objects =
-    ostree_repo_list_objects_set (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS,
-                                  cancellable, error);
+  g_autoptr(GHashTable) objects = NULL;
+  OstreeRepoPruneFlags flags = options->flags;
+  gboolean commit_only = (flags & OSTREE_REPO_PRUNE_FLAGS_COMMIT_ONLY) > 0;
+  if (commit_only) 
+    {
+      if (!ostree_repo_list_commit_objects_starting_with (self, "", &objects, cancellable, error))
+        return FALSE;  
+    } 
+  else
+    {
+      objects =
+        ostree_repo_list_objects_set (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS,
+                                      cancellable, error);
+    }
   if (!objects)
     return FALSE;
 
index 985711702b8783a7517702c984fa64a0d082da9d..b7ed3600974a130502201e93266c1edbd03a7703 100644 (file)
@@ -1261,7 +1261,7 @@ void ostree_repo_commit_traverse_iter_cleanup (void *p);
  * OstreeRepoPruneFlags:
  * @OSTREE_REPO_PRUNE_FLAGS_NONE: No special options for pruning
  * @OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE: Don't actually delete objects
- * @OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY: Do not traverse individual commit objects, only follow refs
+ * @OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY: Do not traverse individual commit objects, only follow refs for reachability calculations
  * @OSTREE_REPO_PRUNE_FLAGS_COMMIT_ONLY: Only traverse commit objects.  (Since 2022.2)
  */
 typedef enum {